package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.DistributionAuditService;
import com.yixun.qfbao.apidto.AddDistributionPremisesReqDto;
import com.yixun.qfbao.apidto.AddDistributionPremisesResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.AddDistributionPremisesReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("AddDistributionPremisesHander")
public class AddDistributionPremisesHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(AddDistributionPremisesHander.class);
    @Autowired
    private DistributionAuditService distributionAuditService;
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        AddDistributionPremisesReqVo req = (AddDistributionPremisesReqVo)reqDto;
        AddDistributionPremisesReqDto reqDto1 = req.getParams();
        BaseResponseDTO<AddDistributionPremisesResDto> res = new BaseResponseDTO<AddDistributionPremisesResDto>();
        AddDistributionPremisesResDto resDto = new AddDistributionPremisesResDto();
        try {
            resDto = distributionAuditService.addDistributionAudit(reqDto1);
        }catch(TServerException e){
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setMessage(e.getErrorMsg());
        } catch (Exception e) {
            logger.error("AddDistributionPremisesHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setMessage("系统异常");
        }
        res.setResData(resDto);
        res.setResult(resDto.getResult());
        return res;
    }
}
